package com.ms.demo;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: ***
 * @author: ms
 * @create: 2022-10-27 16:06
 */
public class Subject {

    //
    private List<Observer> observers = new ArrayList<>();
    private int state;


    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
        notifyAllObservers();
    }

    public void attach(Observer observer){
        observers.add(observer);
    }

    public void notifyAllObservers(){
        for (Observer observer : observers) {
            observer.update();
        }
    }

}